package cn.kgc.mes.routeprocess.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;

import cn.kgc.mes.common.core.plus.response.Result;
import cn.kgc.mes.common.core.plus.response.ResultUtil;
import cn.kgc.mes.common.core.plus.dto.common.CommonDataPageResponse;
import cn.kgc.mes.common.core.plus.response.StatusResponse;

import cn.kgc.mes.routeprocess.domain.vo.RouteProcessVo;
import cn.kgc.mes.routeprocess.business.RouteProcessBusiness;

/**
 * 工艺组成控制器
 * 
 * @author ruoyi
 * @date 2025-09-13
 */
@RestController
@RequestMapping("/routeprocess/routeprocess")
public class RouteProcessController {

    @Resource
    RouteProcessBusiness business;

    /**
     * 分页查询工艺组成列表
     */
//    @PreAuthorize("@ss.hasPermi('routeprocess:routeprocess:list')")
    @PostMapping("/page")
    public Result page(@RequestBody RouteProcessVo vo) {
        CommonDataPageResponse<RouteProcessVo> response = business.page(vo);

        return ResultUtil.success(response);
    }

    /**
     * 获取工艺组成详细信息
     */
//    @PreAuthorize("@ss.hasPermi('routeprocess:routeprocess:query')")
    @PostMapping("/info")
    public Result info(@RequestBody RouteProcessVo vo) {

        RouteProcessVo info = business.info(vo);

        return ResultUtil.success(info);
    }

    /**
     * 新增工艺组成
     */
//    @PreAuthorize("@ss.hasPermi('routeprocess:routeprocess:add')")
    @PostMapping("/add")
    public Result add(@RequestBody RouteProcessVo vo) {

        StatusResponse response = business.add(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 修改工艺组成
     */
//    @PreAuthorize("@ss.hasPermi('routeprocess:routeprocess:edit')")
    @PostMapping("/update")
    public Result update(@RequestBody RouteProcessVo vo) {

        StatusResponse response = business.update(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 删除工艺组成
     */
//    @PreAuthorize("@ss.hasPermi('routeprocess:routeprocess:remove')")
    @PostMapping("/delete")
    public Result delete(@RequestBody RouteProcessVo vo) {

        StatusResponse response = business.delete(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

}
